package org.vincen.springapp.controller;

import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.View;
import org.springframework.web.servlet.view.InternalResourceView;

@Controller
public class SysInfoController {
	
	final Logger logger = LoggerFactory.getLogger(SysInfoController.class);

    @Value("#{messageSource.getMessage('admin.email', '', 'en')}")
    private String email;
    
	@RequestMapping("/about")
	public ModelAndView about(){
	    ModelAndView mav = new ModelAndView();
	    View aboutView = new InternalResourceView("/WEB-INF/jsp/about.jsp");
	    mav.setView(aboutView);
	    mav.addObject("email", email);
	    return mav;
	}
	
	@RequestMapping(value="/about2")
	public void about2(){
	}
//	@RequestMapping(value="/about2", method=RequestMethod.POST)
//	public @ResponseBody String about2(@RequestBody String s){
//		System.out.println(s);
//		String sRes = "hello ";
//		sRes += s;
//		
//		return sRes;
//	}
	
	@RequestMapping(value="/about2/submit", method=RequestMethod.POST, produces="text/plain")
	public @ResponseBody String about2Submit(@RequestParam String sVal, @RequestParam Integer nVal){
		String s = StringUtils.reverse(sVal);
		double n = Math.pow(nVal, 2);
		return s + "," + n;
	}
	
	
	@RequestMapping(value="primitive", method=RequestMethod.GET, produces="application/json")
	public @ResponseBody String primitive(@RequestParam(value="age") Integer value){
		logger.info("input age:{}", value);
		return "Converted primitive " + value + "帅星";
	}
	
}
